<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            思路：定义一个isLeft的变量代表其为左节点，先序遍历树的节点。
            如果当前节点是叶子节点且isLeft为true那么sum+=

            
            */
            var sumOfLeftLeaves = function (root) {
                let sum = 0
                function preOrder(root, isLeft) {
                    if (!root) return
                    if (!root.left && !root.right) {
                        if (isLeft) {
                            sum += root.val
                        }
                    }
                    preOrder(root.left, true)
                    preOrder(root.right, false)
                }
                preOrder(root, false)
                return sum
            }
        </script>
    </body>
</html>
